package com.smartsaas.ugclivii.cd;

import nxopen.NXException;
import nxopen.blockstyler.Node;
import nxopen.blockstyler.Tree;
import nxopen.blockstyler.TreeListMenu;

import java.rmi.RemoteException;

public class EleTreeHandler implements Tree.OnEndLabelEditCallback, Tree.OnBeginLabelEditCallback, Tree.AskEditControlCallback, Tree.OnEditOptionSelectedCallback, Tree.OnStateChangeCallback, Tree.OnMenuCallback, Tree.OnMenuSelectionCallback {
    @Override
    public Tree.ControlType askEditControlCallback(Tree tree, Node node, int i) throws NXException, RemoteException {
        if (i==2){
            String[] op={"定模电极","动模电极","滑块电极","清角电极"};
            tree.setEditOptions(op,0);
            return Tree.ControlType.COMBO_BOX;
        }
        return Tree.ControlType.NONE;
    }

    @Override
    public Tree.BeginLabelEditState onBeginLabelEditCallback(Tree tree, Node node, int i) throws NXException, RemoteException {
        return Tree.BeginLabelEditState.ALLOW;
    }

    @Override
    public Tree.EditControlOption onEditOptionSelectedCallback(Tree tree, Node node, int i, int i1, String s, Tree.ControlType controlType) throws NXException, RemoteException {
        return Tree.EditControlOption.ACCEPT;
    }

    @Override
    public Tree.EndLabelEditState onEndLabelEditCallback(Tree tree, Node node, int i, String s) throws NXException, RemoteException {
        return Tree.EndLabelEditState.ACCEPT_TEXT;
    }

    @Override
    public void onMenuCallback(Tree tree, Node node, int i) throws NXException, RemoteException {
        if(node!=null){
            TreeListMenu menu = tree.createMenu();
            menu.addMenuItem(0,"删除节点","delete");
            tree.setMenu(menu);
        }
    }

    @Override
    public void onMenuSelectionCallback(Tree tree, Node node, int i) throws NXException, RemoteException {
        if (node!=null){
            tree.deleteNode(node);
        }
    }

    @Override
    public void onStateChangeCallback(Tree tree, Node node, int i) throws NXException, RemoteException {
        int state = node.getState()==1?2:1;
        node.setState(state);
    }
}
